#pragma once

#include <iostream>

using namespace std;

#include <queue>
#include <mutex>
#include <atomic>
#include <thread>
#include <memory>
#include <condition_variable>
#include <functional>
#include "client.h"
#include "../utils/log.h"
#include "../constant/constant.h"

class ConnectionPool {
public:
    static ConnectionPool* getInstance();

    shared_ptr<Connection> getConnection();
    ConnectionPool(const ConnectionPool &) = delete;
    ConnectionPool& operator=(const ConnectionPool &) = delete;

private:
    ConnectionPool();
    void produceConnection();
    void scannerConnection();
private:
    static ConnectionPool *pool;
    static mutex checkMutex;
    int maxsize =10;
    int maxIdleTime = 10000;
    int timeoutTime = 60;
    queue<Connection*>  queue_c;
    mutex lock_q;
    atomic_int count;
    condition_variable cv;
};